/*
 * Copyright (C) 2019 Baidu, Inc. All Rights Reserved.
 */
package com.bootdo.hjh.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.bootdo.hjh.dao.provider.StockProvider;
import com.bootdo.hjh.domain.StockDO;

/**
 * 库存变更记录
 *
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2019-04-08 15:26:46
 */
@Mapper
public interface StockDao {

    StockDO get(Integer id);

    List<StockDO> list(Map<String, Object> map);

    int count(Map<String, Object> map);

    int save(StockDO stock);

    int update(StockDO stock);

    int remove(Integer id);

    int batchRemove(Integer[] ids);

    @Select("select sum(amount) from t_stock where user_id = #{userId} and product_type = #{productType}")
    Integer myStockBalance(@Param("userId") Long userId, @Param("productType") Integer productType);

    @SelectProvider(type = StockProvider.class, method = "listStocks")
    List<StockDO> listStocks(@Param("userId") Long userId, @Param("type") Integer type,
                             @Param("beginDate") Date beginDate,
                             @Param("endDate") Date endDate, @Param("offset") Integer offset,
                             @Param("limit") Integer limit);

    @SelectProvider(type = StockProvider.class, method = "countStocks")
    Integer countStocks(@Param("userId") Long userId, @Param("type") Integer type,
                        @Param("beginDate") Date beginDate,
                        @Param("endDate") Date endDate);

    @SelectProvider(type = StockProvider.class, method = "sumStocks")
    Integer sumStocks(@Param("userId") Long userId, @Param("type") Integer type,
                        @Param("beginDate") Date beginDate,
                        @Param("endDate") Date endDate);
}
